//判断是否为二叉排序树 
int pre=-100;
int JudgeBst(BiTree T){
	int b1,b2;
	if(T==NULL)
	   return 1;		  //空树
	b1=JudgeBst(T->lchild)//判断左子树是否为二叉排序树 
	if(b1==0||T->data<pre)//若左子树返回0或者前驱大于当前结点 
	   return 0;
    pre=T->data;
    b2=JudgeBst(T->rchild)//判断右子树 
	return b2;//返回右子树结果 
}



int pre=-100;
bool JudgeBst(BiTree T){
    flag b1,b2;
    if(T==NULL)
        return true;
    b1=JudgeBst(T->left);
    if(!b1||T->data<pre)
        return false;
    pre=T->data;
    b2=JudgeBst(T->right);
    return b2;
}
// 判断二叉树是否为平衡二叉树
//判断树是否为平衡二叉树(1:是 0:不是)
//优化版本(不用遍历重复的结点)
int IsBlancedTree_op(BTNode* root, int *pdepth)
{
    if (root == NULL)
    {
        *pdepth = 0;
        return 1;
    }
    //按照后序遍历去判断,先判断左右子树，然后记录以当前结点为根树的深度
    int left, right;
    if (IsBlancedTree_op(root->_left, &left) && IsBlancedTree_op(root->_right, &right))
    {
        int gap = right - left;
        if (gap <= 1 && gap >= -1)
        {
            *pdepth = left>right ? left + 1 : right + 1;
            return 1;
        }
    }
    return 0;
}


bool IsBlancedTree_op(BiTree root,,int *depth){
    if(root==NULL){
        *depth=1;
        return true;
    }
    int left,right;
    if(IsBlancedTree_op(root->left,&left) && IsBlancedTree_op(root->right,&right)){
        int bf=left-right;
        if(bf<==1 && bf>=-1){
            *depth=left>right?left+1:right+1;
            return 1;
        }
    }
    return 0;
}
